home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Code Resources / Jims CDEFs 1.50 / demo Source ƒ / dynMenu.c < prev    next >
Encoding:
Text File  |  1995-10-27  |  1.9 KB  |  79 lines  |  [TEXT/KAHL]

  1. //----------------------------------------------------------------------------------
  2. // File        : dynMenu.c
  3. // Date        : Dec 28, 1994
  4. // Author    : Jim Stout
  5. //            :
  6. // Purpose    : Example code for implementing a dynamic popup menu
  7. //----------------------------------------------------------------------------------
  8. #include "movableModal.h"
  9. #include "demoDialog.h"
  10.  
  11. static void buildMenu(MenuHandle mHdl, short type);
  12.  
  13. extern void dynMenu()
  14. {
  15.     DialogPtr            theDialog;
  16.     short                itemHit,inx,t;
  17.     Rect                r;
  18.     Handle                h;
  19.     MenuHandle            mHdl;
  20.         
  21. // must create menu before control (which is created by the dialog)
  22.  
  23.     mHdl = NewMenu(210, "\p");
  24.     buildMenu(mHdl, 4);
  25.     InsertMenu(mHdl, -1);
  26.     
  27. // create the dialog
  28.  
  29.     theDialog = GetNewDialog(210,0L,(DialogPtr)-1);
  30.     if(theDialog) {
  31.  
  32.         SetPort(theDialog);    
  33.         
  34.         GetDItem(theDialog, 4, &t, &h, &r);        // set radio button
  35.         SetCtlValue((ControlHandle)h, 1);
  36.         
  37.         ShowWindow(theDialog);
  38.         
  39.         do {
  40.             movableModalDialog(nil,&itemHit);
  41.             switch(itemHit) {
  42.                 case 4:
  43.                 case 5:
  44.                 case 6:
  45.                     for(inx=4;inx<7;inx++) {
  46.                         GetDItem(theDialog, inx, &t, &h, &r);    // toggle radio btn
  47.                         if(inx == itemHit)
  48.                             SetCtlValue((ControlHandle)h, 1);
  49.                         else
  50.                             SetCtlValue((ControlHandle)h, 0);
  51.                             
  52.                         buildMenu(mHdl, itemHit);                // change menu items
  53.                         GetDItem(theDialog, 3, &t, &h, &r);
  54.                         SetCtlValue((ControlHandle)h, 1);        // reset control value
  55.                         Draw1Control((ControlHandle)h);            // force it to redraw
  56.                     }
  57.                 break;
  58.             }
  59.         }while(itemHit != 1 && itemHit != 2);
  60.         DisposDialog(theDialog);
  61.         DeleteMenu(210);
  62.         DisposeMenu(mHdl);
  63.     }
  64. }
  65.  
  66. static void buildMenu(MenuHandle mHdl, short type)
  67. {
  68.     short    inx,max;
  69.     Str255    s;
  70.     
  71.     max = CountMItems(mHdl);
  72.     for(inx=1;inx<=max;inx++)                // remove existing menu items
  73.         DelMenuItem(mHdl, 1);
  74.     max = 6;
  75.     for(inx=1;inx<=max;inx++) {                // add new items to menu
  76.         GetIndString(s,206+type, inx);
  77.         AppendMenu(mHdl, s);
  78.     }
  79. }